#define _GNU_SOURCE
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include <string.h>
#include <gdbm-ndbm.h>
#include <gdk/gdkkeysyms.h>
#include <sys/stat.h>
#include <sys/shm.h>

#include <gtk/gtk.h>
#include <glib.h>
#include <glib/gi18n.h>
#include <glib/gstdio.h>
#include <libintl.h>
#include <locale.h>

#include "invoke_scripts.h"
#include "sig_handle.h"
#include "account_manage.h"
#include "dialogs.h"
#include "global_vars.h"

#define VERSION "0.030-2011-05-28"

#define zh_CN_PACAKGE "njubras-for-linux"
#define zh_CN_PACAKGE_DIR "./lang"

static void is_only_one();
static void reshow_interface(int signum);

static void create_interface();

static void  create_connecting_dialog();
static int progress_bar_pulse(GtkProgressBar *progress_bar);

static void create_tray_icon(GtkWidget *window);
static void popup_menu(GtkStatusIcon *status_icon,guint button,guint activate_time,gpointer user_data);
static void njubras_about();
static void njubras_exit();


int main (int argc, char *argv[])
{
	bindtextdomain(zh_CN_PACAKGE,zh_CN_PACAKGE_DIR);
	textdomain(zh_CN_PACAKGE);

	gtk_init(&argc,&argv);

	umask(0000);

	is_only_one();

	call_daemon("");

	signal(SIGINT,njubras_interrupt);

	create_interface();
	create_tray_icon(window_global);

	gtk_main();

	return 0;
}

void is_only_one()
{
	GtkWidget *error_dialog;

	GIOChannel *lock_file_read_channel;

	GString *proc_id_string;
	gint proc_id;

	GString *proc_status_file;
	GIOChannel *proc_status_file_read_channel;
	GString *line_buffer;

	proc_id_string=g_string_new("");
	proc_status_file=g_string_new("");
	line_buffer=g_string_new("");

	GIOChannel *lock_file_write_channel;

	if (g_access(LOCK_FILE,R_OK|W_OK)==0)
	{
		lock_file_read_channel=g_io_channel_new_file(LOCK_FILE,"r+",NULL);

		if (lock_file_read_channel!=NULL)
		{
			g_io_channel_read_line_string(lock_file_read_channel,proc_id_string,NULL,NULL);

			g_string_assign(proc_status_file,proc_id_string->str);
			g_string_prepend(proc_status_file,"/proc/");
			g_string_append(proc_status_file,"/status");

			if (g_access(proc_status_file->str,R_OK)==0)
			{
				proc_status_file_read_channel=g_io_channel_new_file(proc_status_file->str,"r",NULL);
				g_io_channel_read_line_string(proc_status_file_read_channel,line_buffer,NULL,NULL);

				if (strstr(line_buffer->str,"njubras-for-lin")!=NULL)
				{
					proc_id=(uid_t)atoi(proc_id_string->str);
					kill(proc_id,SIGALRM);

					exit(0);
				}
				else
				{
					g_io_channel_close(lock_file_read_channel);
					g_io_channel_close(proc_status_file_read_channel);
					g_string_free(proc_id_string,TRUE);
					g_string_free(proc_status_file,TRUE);
					g_string_free(line_buffer,TRUE);
				}
			}
			else
			{
				g_io_channel_close(lock_file_read_channel);
				g_string_free(proc_id_string,TRUE);
				g_string_free(proc_status_file,TRUE);
			}
		}
	}
	else if (g_access(LOCK_FILE,F_OK)==0)
	{
		error_dialog=gtk_message_dialog_new(NULL,GTK_DIALOG_NO_FLAG,
																		GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,
																		_("Can't read or write to the lock file."
																		   "\nPlease delete it with the command: "
																		   "\nsudo rm -rf %s"),LOCK_FILE);

		gtk_dialog_run(GTK_DIALOG(error_dialog));
		gtk_widget_destroy(error_dialog);

		exit (1);
	}

	lock_file_write_channel=g_io_channel_new_file(LOCK_FILE,"w+",NULL);

	proc_id=getpid();
	proc_id_string=g_string_sized_new(32);
	sprintf(proc_id_string->str,"%d",proc_id);

	g_io_channel_write_chars(lock_file_write_channel,proc_id_string->str,-1,NULL,NULL);
	g_io_channel_close(lock_file_write_channel);

	g_string_free(proc_id_string,TRUE);
	signal(SIGALRM,reshow_interface);
}

void reshow_interface(int signum)
{
	gtk_widget_show_all(window_global);
}

static void create_interface()
{
	GtkWidget *window;
	GtkWidget *vbox;

	GtkWidget *menu_bar;

	GtkWidget *menu_item_advanced;
	GtkWidget *menu_advanced;
		GtkAccelGroup *menu_advanced_group;
		GtkWidget *menu_item_settings;
		GtkWidget *menu_advanced_separator;
		GtkWidget *menu_item_watchlog;
	GtkWidget *menu_item_help;
	GtkWidget *menu_help;
		GtkAccelGroup *menu_help_group;
		GtkWidget *menu_item_tips;
		GtkWidget *menu_help_separator;
		GtkWidget *menu_item_about;

	GtkWidget *image;

	GtkWidget *hbox_1;
	GtkWidget *username_label;
	GtkWidget *username_entry;

	GtkWidget *hbox_2;
	GtkWidget *password_label;
	GtkWidget *password_entry;

	GtkWidget *hbox_3;
	//GString *account_dir_file_path;
	//GString *account_pag_file_path;
	GtkWidget *check_button_off_campus;
	GtkWidget *check_button_save_account;

	GtkWidget *hbox_4;
	GtkWidget *connect_button;
	GtkWidget *exit_button;

	timer_global=g_timer_new();

	window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
	window_global=window;
	gtk_window_set_title(GTK_WINDOW(window),"Njubras for Linux");
	gtk_window_set_icon_from_file(GTK_WINDOW(window),"./image/njubras-for-linux.png",NULL);
	gtk_window_set_resizable(GTK_WINDOW(window),FALSE);

	vbox=gtk_vbox_new(FALSE,0);
	gtk_container_add(GTK_CONTAINER(window),vbox);

	menu_bar=gtk_menu_bar_new();
	gtk_box_pack_start(GTK_BOX(vbox),menu_bar,TRUE,TRUE,0);

	menu_item_advanced=gtk_menu_item_new_with_mnemonic(_("_Advanced"));
	gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar),menu_item_advanced);
	menu_advanced=gtk_menu_new();
	gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item_advanced),menu_advanced);
	menu_item_settings=gtk_menu_item_new_with_label(_("Settings"));
	gtk_menu_shell_append(GTK_MENU_SHELL(menu_advanced),menu_item_settings);
	menu_advanced_separator=gtk_separator_menu_item_new();
	gtk_menu_shell_append(GTK_MENU_SHELL(menu_advanced),menu_advanced_separator);
	menu_item_watchlog=gtk_menu_item_new_with_label(_("Watch log"));
	gtk_menu_shell_append(GTK_MENU_SHELL(menu_advanced),menu_item_watchlog);

	menu_item_help=gtk_menu_item_new_with_mnemonic(_("_Help"));
	gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar),menu_item_help);
	menu_help=gtk_menu_new();
	gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item_help),menu_help);
	menu_item_tips=gtk_menu_item_new_with_label(_("Tips"));
	gtk_menu_shell_append(GTK_MENU_SHELL(menu_help),menu_item_tips);
	menu_help_separator=gtk_separator_menu_item_new();
	gtk_menu_shell_append(GTK_MENU_SHELL(menu_help),menu_help_separator);
	menu_item_about=gtk_menu_item_new_with_label(_("About"));
	gtk_menu_shell_append(GTK_MENU_SHELL(menu_help),menu_item_about);

	image=gtk_image_new_from_file("./image/tux_surf.png");
	gtk_box_pack_start(GTK_BOX(vbox),image,TRUE,FALSE,0);

	hbox_1=gtk_hbox_new(FALSE,0);
	username_label=gtk_label_new(_("Username: "));
	gtk_label_set_justify(GTK_LABEL(username_label),GTK_JUSTIFY_RIGHT);
	username_entry=gtk_entry_new();
	g_object_set_data(G_OBJECT(window_global),"username_entry",username_entry);
	gtk_entry_set_max_length(GTK_ENTRY(username_entry),USERNAME_MAXLENGTH);
	gtk_box_pack_start(GTK_BOX(hbox_1),username_label,TRUE,TRUE,0);
	gtk_box_pack_start(GTK_BOX(hbox_1),username_entry,FALSE,TRUE,0);
	gtk_box_pack_start(GTK_BOX(vbox),hbox_1,TRUE,FALSE,0);

	hbox_2=gtk_hbox_new(FALSE,0);
	password_label=gtk_label_new(_("Password: "));
	gtk_label_set_justify(GTK_LABEL(password_label),GTK_JUSTIFY_RIGHT);
	password_entry=gtk_entry_new();
	g_object_set_data(G_OBJECT(window_global),"password_entry",password_entry);
	gtk_entry_set_max_length(GTK_ENTRY(password_entry),PASSWORD_MAXLENGTH);
	gtk_entry_set_visibility(GTK_ENTRY(password_entry),FALSE);
	gtk_box_pack_start(GTK_BOX(hbox_2),password_label,TRUE,TRUE,0);
	gtk_box_pack_start(GTK_BOX(hbox_2),password_entry,FALSE,TRUE,0);
	gtk_box_pack_start(GTK_BOX(vbox),hbox_2,TRUE,FALSE,0);

	hbox_3=gtk_hbox_new(FALSE,0);
	check_button_save_account=gtk_check_button_new_with_label(_("Save Account"));

	if (is_account_saved())
	{
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_button_save_account),TRUE);
		read_account();
	}

	g_object_set_data(G_OBJECT(window_global),"check_button_save_account",check_button_save_account);
	check_button_off_campus=gtk_check_button_new_with_label(_("Off Campus"));
	g_object_set_data(G_OBJECT(window_global),"check_button_off_campus",check_button_off_campus);
	gtk_box_pack_start(GTK_BOX(hbox_3),check_button_save_account,TRUE,FALSE,0);
	gtk_box_pack_start(GTK_BOX(hbox_3),check_button_off_campus,TRUE,FALSE,0);
	gtk_box_pack_start(GTK_BOX(vbox),hbox_3,TRUE,FALSE,0);

	hbox_4=gtk_hbox_new(FALSE,0);
	connect_button=gtk_button_new_with_mnemonic(_("_Connect"));
	g_object_set_data(G_OBJECT(window_global),"connect_button",connect_button);
	exit_button=gtk_button_new_with_mnemonic(_("_Exit"));
	gtk_box_pack_start(GTK_BOX(hbox_4),connect_button,TRUE,FALSE,0);
	gtk_box_pack_start(GTK_BOX(hbox_4),exit_button,TRUE,FALSE,0);
	gtk_box_pack_start(GTK_BOX(vbox),hbox_4,TRUE,FALSE,0);

	menu_advanced_group=gtk_accel_group_new();
	gtk_window_add_accel_group(GTK_WINDOW(window),menu_advanced_group);
	gtk_menu_set_accel_group(GTK_MENU(menu_advanced),menu_advanced_group);
	gtk_widget_add_accelerator(menu_item_settings,"activate",menu_advanced_group,GDK_S,\
												  GDK_CONTROL_MASK,GTK_ACCEL_VISIBLE);
	gtk_widget_add_accelerator(menu_item_watchlog,"activate",menu_advanced_group,GDK_W,\
												  GDK_CONTROL_MASK,GTK_ACCEL_VISIBLE);

	menu_help_group=gtk_accel_group_new();
	gtk_window_add_accel_group(GTK_WINDOW(window),menu_help_group);
	gtk_menu_set_accel_group(GTK_MENU(menu_help),menu_help_group);
	gtk_widget_add_accelerator(menu_item_tips,"activate",menu_help_group,GDK_T,\
												  GDK_CONTROL_MASK,GTK_ACCEL_VISIBLE);
	gtk_widget_add_accelerator(menu_item_about,"activate",menu_help_group,GDK_A,\
												  GDK_CONTROL_MASK,GTK_ACCEL_VISIBLE);

	//g_signal_connect(G_OBJECT(window),"destroy",G_CALLBACK(njubras_exit),NULL);
	g_signal_connect(G_OBJECT(window),"delete-event",G_CALLBACK(gtk_widget_hide),NULL);

	g_signal_connect(G_OBJECT(menu_item_settings),"activate",G_CALLBACK(creat_settings_dialog),\
								 NULL);
	g_signal_connect(G_OBJECT(menu_item_watchlog),"activate",G_CALLBACK(creat_watch_log_dialog),\
								 NULL);

	g_signal_connect(G_OBJECT(menu_item_tips),"activate",G_CALLBACK(creat_tips_dialog),\
								 NULL);
	g_signal_connect(G_OBJECT(menu_item_about),"activate",G_CALLBACK(njubras_about),\
								 NULL);
	g_signal_connect(G_OBJECT(connect_button),"clicked",G_CALLBACK(create_connecting_dialog),\
								 NULL);
	g_signal_connect_swapped(G_OBJECT(exit_button),"clicked",G_CALLBACK(njubras_exit),window);

	gtk_widget_show_all(window);

	//g_string_free(account_dir_file_path,TRUE);
	//g_string_free(account_pag_file_path,TRUE);
}

static void create_connecting_dialog()
{
	GtkWidget *dialog;
	GtkWidget *message_dialog;
	GtkWidget *progress_bar;

	GtkWidget *username_entry;
	GtkWidget *password_entry;
	GtkWidget *check_button_save_account;
	GtkWidget *check_button_off_campus;
	GtkWidget *connect_button;

	pid_t forked_pid;

	#define RESPONSE_LENGTH 50

	const int SHM_KEY=ftok(".",'S');

	gchar *response_shared;
	pid_t  shm_id;
	gint times_left;
	double interval;

	gint dialog_return;
	gint dialog_x;
	gint dialog_y;

	GIOChannel *message_read_channel=NULL;

	GString *response_message=g_string_new("");
	gsize terminator_pos=-1;

	username_entry=g_object_get_data(G_OBJECT(window_global),"username_entry");
	password_entry=g_object_get_data(G_OBJECT(window_global),"password_entry");

	check_button_save_account=g_object_get_data(G_OBJECT(window_global),"check_button_save_account");
	check_button_off_campus=g_object_get_data(G_OBJECT(window_global),"check_button_off_campus");

	connect_button=g_object_get_data(G_OBJECT(window_global),"connect_button");

	if (strlen(gtk_entry_get_text(GTK_ENTRY(username_entry)))==0)
	{
		message_dialog=gtk_message_dialog_new(NULL,GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,\
												GTK_BUTTONS_CLOSE,_("\nYour username can't be empty!"));
		gtk_dialog_run(GTK_DIALOG(message_dialog));
		gtk_widget_destroy(message_dialog);
		gtk_widget_grab_focus(username_entry);
		return;
	}

	if (strlen(gtk_entry_get_text(GTK_ENTRY(password_entry)))==0)
	{
		message_dialog=gtk_message_dialog_new(NULL,GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,\
												GTK_BUTTONS_CLOSE,_("\nYour password can't be empty!"));
		gtk_dialog_run(GTK_DIALOG(message_dialog));
		gtk_widget_destroy(message_dialog);
		gtk_widget_grab_focus(password_entry);
		return;
	}

	bras_connect();

	dialog=gtk_dialog_new_with_buttons(_("Connecting"),NULL,GTK_DIALOG_NO_SEPARATOR|\
																GTK_DIALOG_MODAL,\
																_("Cancel"),GTK_RESPONSE_CANCEL,NULL);
	gtk_window_set_icon_from_file(GTK_WINDOW(dialog),"./image/connecting.png",NULL);
	dialog_global=dialog;
	gtk_widget_set_size_request(dialog,350,70);

	gtk_window_set_resizable(GTK_WINDOW(dialog),FALSE);
	progress_bar=gtk_progress_bar_new();
	gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress_bar),_("Please Waiting..."));
	gtk_progress_bar_set_pulse_step(GTK_PROGRESS_BAR(progress_bar),0.008);

	g_timeout_add(5,(GSourceFunc)(progress_bar_pulse),progress_bar);
	gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),progress_bar,FALSE,FALSE,3);

	gtk_widget_show_all(dialog);

	forked_pid=fork();

	switch (forked_pid)
	{
		case (-1):
			perror("Njubras-for-linux: ");
			exit(1);

		case 0:

			if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check_button_save_account)))
				save_account();
			else
				remove_account();

			times_left=4;
			interval=0.5;

			message_read_channel=g_io_channel_new_file("./log/connect_result","r",NULL);

			while (times_left>=0)
			{
				sleep(interval);

				message_read_channel=g_io_channel_new_file("./log/connect_result","r",NULL);

				if (message_read_channel!=NULL)
					break;

				times_left--;
			}

			if (message_read_channel==NULL)
			{
				g_string_assign(response_message,"Can't find the log file.");
				goto emit_signal;
			}

			times_left=5;
			interval=3;

			while (times_left>=0)
			{

				sleep(interval);

				g_io_channel_read_line_string(message_read_channel,response_message,&terminator_pos,NULL);

				if (response_message->str[0]!='?')
					goto emit_signal;
				g_io_channel_seek_position(message_read_channel,0,G_SEEK_SET,NULL);

				times_left--;
			}

emit_signal:
			if ((message_read_channel==NULL)||(strncmp(response_message->str,
				  ANSWER_WHEN_SUCCESS,10)))
			{
				kill(getppid(),SIGUSR1);

				shm_id=shmget(SHM_KEY,RESPONSE_LENGTH+1,0666|IPC_CREAT);
				response_shared=shmat(shm_id,NULL,0);
				memset(response_shared,'\0',RESPONSE_LENGTH+1);
				snprintf(response_shared,RESPONSE_LENGTH,"%s",response_message->str);

				g_string_free(response_message,TRUE);
				shmdt(response_shared);

				exit(1);
			}
			else
			{
				kill(getppid(),SIGUSR2);
				g_string_free(response_message,TRUE);
				exit(0);
			}
	}

	signal(SIGUSR1,dialog_response);
	signal(SIGUSR2,dialog_response);
	signal(SIGCHLD,SIG_IGN);

	dialog_exist=TRUE;
	dialog_return=gtk_dialog_run(GTK_DIALOG(dialog));

	gtk_window_get_position(GTK_WINDOW(dialog),&dialog_x,&dialog_y);

	switch (dialog_return)
	{
		case GTK_RESPONSE_REJECT:
			dialog_exist=FALSE;

			call_daemon("bash bras_control.sh kill &");

			shm_id=shmget(SHM_KEY,RESPONSE_LENGTH,0666|IPC_CREAT);
			response_shared=shmat(shm_id,NULL,0);

			g_source_remove_by_user_data(progress_bar);
			gtk_widget_destroy(dialog);
			message_dialog=gtk_message_dialog_new(GTK_WINDOW(window_global),\
																				   GTK_DIALOG_DESTROY_WITH_PARENT,\
																				   GTK_MESSAGE_ERROR,GTK_BUTTONS_CLOSE,\
																				   "%s",response_shared);
			g_signal_connect_swapped(G_OBJECT(message_dialog),"response",\
														  G_CALLBACK(gtk_widget_destroy),message_dialog);
			gtk_window_move(GTK_WINDOW(message_dialog),dialog_x+61,dialog_y);
			gtk_widget_show_all(message_dialog);

			g_string_free(response_message,TRUE);
			shmdt(response_shared);
			shmctl(shm_id,IPC_RMID,0);

			break;

		case GTK_RESPONSE_CANCEL:
			call_daemon("bash bras_control.sh kill &");
			kill(forked_pid,SIGKILL);
			bras_disconnect();
			dialog_exist=FALSE;
			g_source_remove_by_user_data((gpointer)progress_bar);
			gtk_widget_destroy(dialog);
			break;

		case GTK_RESPONSE_ACCEPT:
			g_timer_start(timer_global);

			g_timeout_add(7000,(GSourceFunc)(check_bras_connect),NULL);
			g_source_remove_by_user_data((gpointer)progress_bar);
			gtk_widget_destroy(dialog);

			gtk_widget_hide(window_global);

			gtk_widget_set_sensitive(username_entry,FALSE);
			gtk_widget_set_sensitive(password_entry,FALSE);
			gtk_widget_set_sensitive(check_button_save_account,FALSE);
			gtk_widget_set_sensitive(check_button_off_campus,FALSE);
			gtk_widget_set_sensitive(connect_button,FALSE);

			break;
	}

}

static int progress_bar_pulse(GtkProgressBar *progress_bar)
{
	gtk_progress_bar_pulse(progress_bar);

	return TRUE;
}


static void create_tray_icon(GtkWidget *window)
{
	GtkStatusIcon *connect_status_icon;

	connect_status_icon=gtk_status_icon_new_from_file("./image/offline.png");
	gtk_status_icon_set_visible(connect_status_icon,TRUE);
	connect_status_icon_global=connect_status_icon;

	disconnect_enable=FALSE;
	gtk_status_icon_set_tooltip_text(connect_status_icon,_("Disconnected"));

	g_signal_connect(connect_status_icon,"popup-menu",G_CALLBACK(popup_menu),NULL);
	g_signal_connect_swapped(connect_status_icon,"activate",G_CALLBACK(gtk_widget_show_all),window_global);
}

static void popup_menu(GtkStatusIcon *status_icon,guint button,guint activate_time,gpointer user_data)
{
	GtkWidget *menu;
	GtkWidget *menu_item_disconnect;
	GtkWidget *menu_seperater;
	GtkWidget *menu_item_about;

	menu=gtk_menu_new();

	menu_item_disconnect=gtk_menu_item_new_with_label(_("Disconnect"));
	gtk_menu_shell_append(GTK_MENU_SHELL(menu),menu_item_disconnect);

	menu_seperater=gtk_separator_menu_item_new();
	gtk_menu_shell_append(GTK_MENU_SHELL(menu),menu_seperater);

	menu_item_about=gtk_menu_item_new_with_label(_("About"));
	gtk_menu_shell_append(GTK_MENU_SHELL(menu),menu_item_about);

	gtk_widget_set_sensitive(menu_item_disconnect,disconnect_enable);
	gtk_widget_show_all(menu);

	gtk_menu_popup(GTK_MENU(menu),NULL,NULL,gtk_status_icon_position_menu,status_icon,button,activate_time);

	g_signal_connect(menu_item_about,"activate",G_CALLBACK(njubras_about),NULL);
	g_signal_connect(menu_item_disconnect,"activate",G_CALLBACK(njubras_exit),NULL);
}

static void njubras_about()
{
	GtkWidget *about_dialog;

	const gchar *authors[]={"Wu Xiaoxiao(nanjingabcdefg@163.com)",NULL};

	GdkPixbuf *logo;

	gchar *license_content;
	GIOChannel *read_license_channel;

	read_license_channel=g_io_channel_new_file("./license/GPLv3","r",NULL);
	g_io_channel_read_to_end(read_license_channel,&license_content,NULL,NULL);

	about_dialog=gtk_about_dialog_new();
	gtk_window_set_icon_from_file(GTK_WINDOW(about_dialog),"./image/info.png",NULL);

	logo=gdk_pixbuf_new_from_file("./image/njubras-for-linux.png",NULL);

	gtk_about_dialog_set_name(GTK_ABOUT_DIALOG(about_dialog),"Njubras for Linux\n");
	gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(about_dialog),VERSION);
	gtk_about_dialog_set_logo(GTK_ABOUT_DIALOG(about_dialog),logo);
	gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(about_dialog),"(C) 2010-2011 Wu Xiaoxiao");
	gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(about_dialog),\
																"http://code.google.com/p/njubras-for-linux/");
	gtk_about_dialog_set_website_label(	GTK_ABOUT_DIALOG(about_dialog),"Host on Code Google");
	gtk_about_dialog_set_authors(GTK_ABOUT_DIALOG(about_dialog),authors);
	gtk_about_dialog_set_license(GTK_ABOUT_DIALOG(about_dialog),license_content);

	gtk_widget_show_all(about_dialog);

	gtk_dialog_run(GTK_DIALOG(about_dialog));

	g_io_channel_close(read_license_channel);
	gtk_widget_destroy(about_dialog);
	g_object_unref(G_OBJECT(logo));
}


static void njubras_exit(GtkWidget *window)
{
	njubras_interrupt(0);
}


